package worldinruin.gui.imp.gameview;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.GroupLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.LayoutStyle;
import javax.swing.SwingConstants;

import worldinruin.core.imp.battle.Battle;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class BattleMainPanel extends javax.swing.JPanel {

	private JLabel attackerLabel;
	private JPanel TroopsPanel;
	private JLabel defenderLabel;
	private Battle battle;
	
	
	/**
	 * Creates a battle main panel.
	 */
	public BattleMainPanel() {
		super();
		initGUI();
	}
	
	/**
	 * Creates a battle main panel with the battle object.
	 * @param battle
	 */
	public BattleMainPanel(Battle battle) {
		super();
		this.battle = battle;
		initGUI();
		setupGUI();
	}
	
	/**
	 * Setup GUI.
	 */
	private void setupGUI() {
		attackerLabel.setText(battle.getAtkPlayer().getName());
		defenderLabel.setText(battle.getDefPlayer().getName());
		TroopsPanel.add(new BattleTroopPanel(battle.getAttacker()));
		TroopsPanel.add(new BattleTroopPanel(battle.getDefender()));
	}

	/**
	 * Initiate GUI.
	 */
	private void initGUI() {
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			setPreferredSize(new Dimension(400, 300));
			{
				attackerLabel = new JLabel();
				attackerLabel.setText("attacker");
			}
			{
				defenderLabel = new JLabel();
				defenderLabel.setText("defender");
			}
			{
				TroopsPanel = new JPanel();
				GridLayout TroopsPanelLayout = new GridLayout(1, 2);
				TroopsPanelLayout.setColumns(2);
				TroopsPanelLayout.setHgap(5);
				TroopsPanelLayout.setVgap(5);
				TroopsPanel.setLayout(TroopsPanelLayout);
			}
				thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					    .addComponent(attackerLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					    .addComponent(defenderLabel, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addComponent(TroopsPanel, 0, 261, Short.MAX_VALUE));
				thisLayout.setHorizontalGroup(thisLayout.createParallelGroup()
					.addComponent(TroopsPanel, GroupLayout.Alignment.LEADING, 0, 400, Short.MAX_VALUE)
					.addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
					    .addGap(27)
					    .addComponent(attackerLabel, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE)
					    .addGap(150)
					    .addComponent(defenderLabel, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE)
					    .addContainerGap(27, Short.MAX_VALUE)));
				thisLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {attackerLabel, defenderLabel});
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
